import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
export const Layout = () => import("@/layout/index.vue");


// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
    {
        path: '/login',
        component: () => import("@/views/login/index.vue")
    },
    // {
    //     path: '/404',
    //     component: () => import('@/views/404'),
    //     hidden: true
    // },
    {
        path: "/",
        component: Layout,
        redirect: "/home",
        name: "home",
        children: [
            {
                path: "/home",
                name: "home", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
                component: () => import("@/views/home/index.vue"),
                meta: {
                    title: "首页"
                },
            },
        ],
    },
    {
        path: "/schoolList",
        component: Layout,
        redirect: "/schoolList",
        name: "schoolList",
        children: [
            {
                path: "/schoolList",
                name: "schoolList",
                component: () => import("@/views/school/schoolList.vue"),
                meta: {
                    title: "学校管理"
                },
            },
            {
                path: "/schoolCode",
                name: "schoolCode",
                component: () => import("@/views/school/schoolCode.vue"),
                meta: {
                    title: "学校二维码"
                },
            },
            {
                path: "/schoolSite",
                name: "schoolSite",
                component: () => import("@/views/school/schoolSite.vue"),
                meta: {
                    title: "地址管理"
                },
            }
        ],
    },
];

/**
 * 创建路由
 */
const router = createRouter({
    history: createWebHashHistory(),
    routes: constantRoutes as RouteRecordRaw[],
    // 刷新时，滚动条位置还原
    scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
    router.replace({ path: "/login" });
}

export default router;